package Classes.GameDatas// ActionScript file
{
	import Classes.GameViews.ViewDisplayers.MapTargets.MapMoveTargets.MapNPCs.MN_SickMan;
	import Classes.Interfaces.I_TimeUnit;
	import Classes.Managers.M_ConfigData;
	import Classes.Managers.M_Timer;

	/**
	 *病人类 
	 * @author 葛增文
	 * 
	 */	
	public class GD_SickMan extends GameData implements I_TimeUnit
	{
		private var _map:GD_Map;/*所属地图*/
		private var _serverID:Number;/*服务器ID*/
		private var _sickManID:Number;/*病人配置ID*/
		private var _configXML:XML;/*病人配置数据*/
		private var _cureTime:Number;/*已经治疗的时间*/
		private var _isUpdateTime:Boolean;/*是否处于记时状态*/
		private var _view:MN_SickMan;/*病人显示对象*/
		public function GD_SickMan(sickManID:Number,serverID:Number):void
		{
			this._serverID=serverID;
			this._sickManID=sickManID;
			this.init();
		}
		
		private function init():void
		{
			var mainXML:XML=M_ConfigData.instance.getXMLByName("病人配置表");
			this._configXML=mainXML.sickMan.(configID==this.sickManID);
		}
		
		/**
		 *创建一个病人数据对象 
		 * @param creatObj 创建数据对象
		 * @return 病人数据对象
		 * 
		 */		
		public static function creat(creatObj:Object,map:GD_Map):GD_SickMan
		{
			var creatTarget:GD_SickMan=new GD_SickMan(creatObj.sickManID,creatObj.serverID);
			creatTarget._map=map;
			return creatTarget
		}
		
		/**
		 *设定治疗时间 
		 * 
		 */		
		public function setCureTime(time:Number):void
		{
			this.cureTime=time;
			if(this.cureTime && !this.isUpdateTime)M_Timer.instance.joinUnit(this);
		}
		
		override public function release():void
		{
			super.release();
			this.isUpdateTime=false;
			if(this._view)
			{
				this._view.release();
				this._view=null;
			}
			this._configXML=null;
		}
		
		/**
		 *记时 
		 * 
		 */		
		public function timeUpdate():void
		{
			this.cureTime+=1;
		}

		/*getter & setter*/
		public function get serverID():Number
		{
			return _serverID;
		}

		public function get sickManID():Number
		{
			return _sickManID;
		}

		public function get configXML():XML
		{
			return _configXML;
		}

		public function get cureTime():Number
		{
			return _cureTime;
		}

		public function set cureTime(value:Number):void
		{
			_cureTime = value;
		}
		
		public function get needCureTime():Number
		{
			return this.configXML.needCureTime;
		}
		
		public function get speed():Number
		{
			return this.configXML.speed;
		}

		public function get isUpdateTime():Boolean
		{
			return _isUpdateTime;
		}

		public function set isUpdateTime(value:Boolean):void
		{
			_isUpdateTime = value;
		}

		public function get view():MN_SickMan
		{
			if(_view)_view=MN_SickMan.creat(this);
			return _view;
		}

		public function get map():GD_Map
		{
			return _map;
		}


	}
}